package cn.wl._04_direct;

import cn.wl.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

public class Send {
    public static final String EXCHANGE_NAME_DIRECT = "my_rabbitmq_direct";

    public static void main(String[] args) throws Exception {
        //获取连接
        Connection connection = ConnectionUtil.getConnection();
        //获取通道
        Channel channel = connection.createChannel();
        //声明一个交换机,指定类型为fanout广播
        channel.exchangeDeclare(
                EXCHANGE_NAME_DIRECT,//交换机名字
                "direct"); //交换机的类型
        //准备一条消息
        String message = "我是hello哈哈哈";
        //发送消息
        channel.basicPublish(
                EXCHANGE_NAME_DIRECT,             //使用自己创建的交换机
                "delete", //路由的key，可以看成是消息队列的名字，要将消息发送给哪个队列
                null,               //额外的参数
                message.getBytes()          //消息的内容
        );
        channel.close();
        connection.close();

    }
}
